//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.moon.back.util;

import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import javax.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

@Component
public class MoonRedisStringUtil {
    private final Logger logger = LoggerFactory.getLogger(MoonRedisStringUtil.class);
    @Resource
    private RedisTemplate<String, Object> redisTemplate;

    public MoonRedisStringUtil() {
    }

    public Object get(String key) {
        return this.redisTemplate.opsForValue().get(key);
    }

    public Boolean set(String key, Object value) {
        try {
            this.redisTemplate.opsForValue().set(key, value);
            return true;
        } catch (Exception e) {
            this.logger.error("redis set value exception!", e);
            return false;
        }
    }

    public Boolean setex(String key, Object value, long expire) {
        try {
            this.redisTemplate.opsForValue().set(key, value, expire, TimeUnit.SECONDS);
            return true;
        } catch (Exception var6) {
            return false;
        }
    }

    public Boolean expire(String key, long expire) {
        return this.expire(key, expire, TimeUnit.SECONDS);
    }

    public Boolean expire(String key, long expire, TimeUnit timeUnit) {
        return this.redisTemplate.expire(key, expire, timeUnit);
    }

    public Long ttl(String key) {
        return this.redisTemplate.getExpire(key);
    }

    public void del(String... keys) {
        if (keys != null && keys.length > 0) {
            this.redisTemplate.delete(Arrays.asList(keys));
        }

    }

    public Long increment(String key) {
        return this.redisTemplate.opsForValue().increment(key);
    }

    public Long incrementAndExpire(String key, long expire, TimeUnit unit) {
        Long incrData = this.increment(key);
        this.expire(key, expire, unit);
        return incrData;
    }

    public Long incrBy(String key, long step) {
        return this.redisTemplate.opsForValue().increment(key, step);
    }

    public Boolean setnx(String key, Object value) {
        return this.redisTemplate.opsForValue().setIfAbsent(key, value);
    }

    public Boolean setnxAndExpire(String key, Object value, long expire) {
        return this.redisTemplate.opsForValue().setIfAbsent(key, value, expire, TimeUnit.SECONDS);
    }

    public Boolean setIfAbsent(String key, Object value, long expire, TimeUnit unit) {
        return this.redisTemplate.opsForValue().setIfAbsent(key, value, expire, unit);
    }

    public Object getAndSet(String key, Object value) {
        return this.redisTemplate.opsForValue().getAndSet(key, value);
    }

    public Boolean hasKey(String key) {
        return this.redisTemplate.hasKey(key);
    }

    public Long addKeyToSet(String key, Object... values) {
        Long result = this.redisTemplate.opsForSet().add(key, values);
        return result;
    }
}